import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;

public class vridhi {
	
	public String splitDevanagari(String word, Map<String, String> dict){
		String a = null;
		
		for(int i = 0; i < word.length()-1; i++){
			if(word.substring(i, i+1).equals("ै")){
				String w1 = word.substring(0, i);
				String w3 = "ए" + word.substring(i+1);
				String w2 = "ऐ" + word.substring(i+1);
				if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}//end if
				else if(dict.containsKey(w1) && dict.containsKey(w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end if
			else if(word.substring(i, i+1).equals("ौ")){
				String w1 = word.substring(0, i);
				String w2 = "अौ" + word.substring(i+1);
				String w3 = "अो" + word.substring(i+1);
				if(dict.containsKey(w1) && dict.containsKey(w2)){
					a = w1 + " " + w2;
					return a;
				}
				else if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}
			}
		}//end for
		return null;
	}//end method
	
	public String split(String word, Map<String, String> dict){
		String a = splitDevanagari(word, dict);
		if (a != null)
			return a;
		for(int i = 0; i < word.length()-2; i++){
			if(word.substring(i, i+2).equals("ai")){
				String w1 = word.substring(0, i+1);
				String w2 = word.substring(0, i+1) + "a";
				String w3 = "e" + word.substring(i+2);
				String w4 = word.substring(i);
				if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}//end if
				else if(dict.containsKey(w2) && dict.containsKey(w3)){
					a = w2 + " " + w3;
					return a;
				}
				else if(dict.containsKey(w1) && dict.containsKey(w4)){
					a = w1 + " " + w4;
					return a;
				}
				else if(dict.containsKey(w2) && dict.containsKey(w4)){
					a = w2 + " " + w4;
					return a;
				}
			}//end if
			else if(word.substring(i, i+2).equals("au")){
				String w1 = word.substring(0, i) + "a";
				String w2 = "o" + word.substring(i+2);
				String w3 = word.substring(i);
				String w4 = word.substring(0, i) + "aa";
				if(dict.containsKey(w1) && dict.containsKey(w2)){
					a = w1 + " " + w2;
					return a;
				}
				else if(dict.containsKey(w1) && dict.containsKey(w3)){
					a = w1 + " " + w3;
					return a;
				}
				else if(dict.containsKey(w4) && dict.containsKey(w3)){
					a = w4 + " " + w3;
					return a;
				}
			}
		}//end for
		return "Word doesn't contain sandhi.";
	}//end method
}//end class
